﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Utilities.Observer
{
    public abstract class Listen
    {
        private IList<Model> events = new List<Model>();
        public Listen()
        {
            //TODO You Can Register Event;
        }

        public virtual void Register(string resourceName, IProcess resource)
        {
            if (resource != null)
            {
                Model item = new Model() { ResourceName = resourceName, Resource = resource };
                if (!events.Contains(item))
                    events.Add(item);
            }
        }
        public virtual void Remove(string resourseName)
        {
            foreach (Model p in events.Where<Model>(p => p.ResourceName == resourseName))
            {
                events.Remove(p);
            }
        }

        public virtual void Notify(System.Web.HttpContextBase context, IList<Object> param)
        {
            //TODO
            foreach (Model p in events)
            {
                p.Resource.OnNext(context, param);
            }
        }
    }
}
